package com.chocho.consumeserver.utils;

import javax.websocket.Session;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author VX5
 * @Title: MJC
 * @ProjectName judge-sql
 * @Description: TODO
 * @date ${DAT}15:13
 */

public class SocketManager {

    /**
     * 用于保存当前所有的websocket连接信息
     */
    private Map<String, Session> sessionMap = new ConcurrentHashMap<>();

    private volatile static SocketManager socketManager;

    public Map<String, Session> getSessionMap() {
        return sessionMap;
    }

    public void setSessionMap(Map<String, Session> sessionMap) {
        this.sessionMap = sessionMap;
    }

    private SocketManager() {
    }

    /**
     * 单例模式
     * @return
     */
    public static SocketManager getInstance(){
        if (socketManager==null){
            synchronized (SocketManager.class){
                if (socketManager==null){
                    socketManager = new SocketManager();
                }
            }
        }
        return socketManager;
    }
}
